(function($){
  if(!window.anthill) anthill={};
  if(!anthill.websockets) anthill.websockets = {};

  anthill.websockets.Marker = function(options) {
    for(var i in options) {
      if(i != 'ws') this.set(i, options[i]);
    }
    if(options.ws) {
      this.buildSocket(options.ws);
    }
  };

  anthill.websockets.Marker.prototype = new google.maps.Marker();

  anthill.websockets.Marker.prototype.buildSocket = function(ws) {
    this.set('socket', io.connect(anthill.ws_url+'/'+ws+'/browser'));
    var mrk = this;
    var evts = {
      updatePosition: function(pos) {
	google.maps.event.trigger(mrk, 'updatePosition', pos);
      }
    };
    for(var i in evts) {
      this.get('socket').on(i, evts[i]);
    }
  };
})(jQuery);